package rm.ep.shared;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.googlecode.objectify.annotation.Unindexed;


@SuppressWarnings("serial")
public class SubscriberEntity extends AbstractEntity {

	// initially it is inactive
	private Boolean fIsActive;
	
	private String fEmail;
	
	@Unindexed
	private Integer fPassword;
	
	private List<String> keywords = new ArrayList<String>();
	
	
	protected SubscriberEntity() {
		// GWT required empty constructor
	}
	
	public SubscriberEntity(String email) {
		if (email == null || !Validator.isEmail(email)) {
			throw new IllegalArgumentException("Invalid Email.");
		}
		fEmail = email.toLowerCase();
		fPassword = RANDOMIZER.nextInt();
		fIsActive = Boolean.FALSE;
	}
	
	public final Boolean isActive() {
		return fIsActive;
	}
	
	public final void setActive(Boolean isActive) {
		fIsActive = isActive;
	}
	
	public final String getEmail() {
		return fEmail;
	}
	
	public final void setKeywords(List<String> keys) {
		keywords.clear();
		keywords.addAll(keys);
	}
	
	public final Integer resetPassword() {
		fPassword = RANDOMIZER.nextInt();
		return fPassword;
	}
	
	public final Integer getPassword() {
		return fPassword;
	}
	
	public final List<String> getKeywords() {
		return Collections.unmodifiableList(keywords);
	}
	
}
